package com.example.administrator.college02.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.college02.BaseFragment;
import com.example.administrator.college02.R;
import com.example.administrator.college02.adapter.MyFragmentPagerAdapter;
import com.example.administrator.college02.pager.ColorTrackView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/7/11.
 */
public class SchoolFragment extends BaseFragment {


    private List<ColorTrackView> mTabs = new ArrayList<>();
    @BindView(R.id.id_tab_01) ColorTrackView tab1;
    @BindView(R.id.id_tab_02) ColorTrackView tab2;
    ArrayList<Fragment> mViews;
    @BindView(R.id.id_viewpager) ViewPager mViewPager;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_school_layout, container, false);
        unbinder = ButterKnife.bind(this, view);
        mTabs.add(tab1);
        mTabs.add(tab2);
        initViews();
        initEvents();
        return view;
    }
    private void initEvents() {
        mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {
            }

            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                if (positionOffset > 0) {
                    ColorTrackView left = mTabs.get(position);
                    ColorTrackView right = mTabs.get(position + 1);
                    left.setDirection(1);
                    right.setDirection(0);
//                    Log.e("TAG", positionOffset+"");
                    left.setProgress(1 - positionOffset);
                    right.setProgress(positionOffset);
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {
            }
        });
    }
    public void initViews() {
        mViews = new ArrayList<>();
        FragmentSchoolChild fragmentSchoolChild = new FragmentSchoolChild();
        FragmentSocietyChild fragmentSocietyChild = new FragmentSocietyChild();
        mViews.add(fragmentSchoolChild);
        mViews.add(fragmentSocietyChild);
        mViewPager.setAdapter(new MyFragmentPagerAdapter(getChildFragmentManager(), mViews));
    }
    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}

